MODULE PRMTRS_STMAS

  ! LAPS PARAMETERS
  CHARACTER*9          :: LAPSAST            ! LAPS ASCII TIME
  INTEGER              :: LAPSI4T            ! LAPS I4TIME
  INTEGER              :: ICYCLE	     ! LAPS CYCLE TIME
  INTEGER              :: UNIFORM            ! 1 UNIFORM VERTICAL GRID

  REAL                 :: RMISSING           ! LAPS DEFAULT MISSING VALUE (YUANFU)
  REAL                 :: BADSFCDT           ! LAPS DEFAULT BAD SURFACE (YUANFU)
  REAL    ,ALLOCATABLE :: LATITUDE(:,:)      ! LAPS LATITUDE OF THE GRID (YUANFU)
  REAL    ,ALLOCATABLE :: LONGITUD(:,:)      ! LAPS LONGITUDE OF THE GRID (YUANFU)
  REAL    ,ALLOCATABLE :: TOPOGRPH(:,:)      ! LAPS LONGITUDE OF THE GRID (YUANFU)
  ! REAL    ,ALLOCATABLE :: LAPSRADW(:)        ! LAPS RADIAL WIND (YUANFU)
  REAL    ,ALLOCATABLE :: Z_FCSTGD(:)        ! VERTICAL LEVEL OF MODEL OR LAPS

  ! END OF LAPS PARAMETERS.

  ! GPS PROCESSING PARAMETERS:
  ! SPECIFIC GAS CONSTANT FOR WATER VAPOR:
  REAL    ,  PARAMETER :: RV_GAS=461
  ! COEFFICIENTS OF REFRACTIVITY AT MICROWAVE FREQUENCIES:
  REAL    ,  PARAMETER :: K2_RFC=22.1
  REAL    ,  PARAMETER :: K3_RFC=373900

  ! BUFR PARAMETERS:
  REAL    ,  PARAMETER :: BUFRMISS = 10.0E10 ! MISSING VALUE IN REAL FOR BUFR DATA

  INTEGER ,  PARAMETER :: MAXDIMS=4          ! NUMBER OF TOTAL DIMENSION
  INTEGER ,  PARAMETER :: TMGOBS_CHANNEL=32  ! CHANNEL FOR TMG FILE
  INTEGER ,  PARAMETER :: PIGOBS_CHANNEL=33  ! CHANNEL FOR TMG FILE
  INTEGER              :: BGTHOBS            ! NOT USE BACKGROUND UNTIL NOBSGRID LESS THAN BGTHOBS
  INTEGER              :: GRDLEVL            ! GRID LEVEL
  INTEGER              :: NUMGRID(MAXDIMS)   ! NUMBER OF GRID FOR EVERY DIMENSION
  INTEGER              :: INIGRID(MAXDIMS)   ! INITIAL NUMBER OF GRID FOR EVERY DIMENSION
  INTEGER              :: MAXGRID(MAXDIMS)   ! MAX NUMBER OF GRID FOR EVERY DIMENSION
  INTEGER              :: NTMPGRD(MAXDIMS)   ! NUMBER OF OLD GRID FOR EVERY DIMENSION
  INTEGER              :: FCSTGRD(MAXDIMS)   ! NUMBER OF OLD GRID FOR EVERY DIMENSION
  INTEGER              :: NUMDIMS            ! NUMBER OF DIMENSION VALID
  INTEGER              :: NGPTOBS            ! NUMBER OF GRID POINT PER OBSERVATION
  INTEGER              :: NUMSTAT            ! NUMBER OF STATE
  INTEGER              :: NALLOBS            ! NUMBER OF TOTAL OBSERVATION VALID
  INTEGER ,ALLOCATABLE :: NOBSTAT(:)         ! NUMBER OF VARIETY OF OBSERVATION VALID
  INTEGER(8)           :: NUMVARS            ! NUMBER OF TOTAL CONTROL VARIABLES VALID
  INTEGER              :: IFBKGND            ! WHETHER USE BACKGROUND OR NOT, 1 IS YES, 0 IS NOT
  INTEGER              :: IFBOUND            ! WHETHER USE BOUND OR NOT, 1 IS YES, 0 IS NOT
  INTEGER              :: IFPCDNT            ! WHETHER USE PURE PRESSURE COORDINATE, 1 IS YES, 0 IS NOT
  INTEGER              :: IF_TEST            ! WHETHER RUN FOR TEST CASE, 1 IS FOR THE TEST CASE, ADDED BY ZHONGJIE HE
  INTEGER              :: FNSTGRD            ! THE FINEST GRID LEVEL
  INTEGER              :: IFREPET            ! WHETHERE RUN THE MUTIGRID FRAME IN MONOTONOUS OR REPEATEDLY, 0 FOR MONOTONOUS, 1 FOR REPEATEDLY
  INTEGER              :: ITREPET            ! THE TIMES TO REPEAT

  REAL    ,ALLOCATABLE :: PENAL0X(:)         ! INITIAL X DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL0Y(:)         ! INITIAL Y DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL0Z(:)         ! INITIAL Z DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL0T(:)         ! INITIAL T DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL_X(:)         ! X DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL_Y(:)         ! Y DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL_Z(:)         ! Z DIRECTION PENALTY COEFFICENT
  REAL    ,ALLOCATABLE :: PENAL_T(:)         ! T DIRECTION PENALTY COEFFICENT
  REAL                 :: PNLT0PU            ! INITIAL GEOSTROPHIC BALANCE PENALTY COEFFICENT, FOR P AND U
  REAL                 :: PNLT0PV            ! INITIAL GEOSTROPHIC BALANCE PENALTY COEFFICENT, FOR P AND V
  REAL                 :: PNLT_PU            ! GEOSTROPHIC BALANCE PENALTY COEFFICENT, FOR P AND U
  REAL                 :: PNLT_PV            ! GEOSTROPHIC BALANCE PENALTY COEFFICENT, FOR P AND V
  REAL                 :: GRDSPAC(MAXDIMS)   ! GRID SPACING
  REAL                 :: ORIPSTN(MAXDIMS)   ! ORIGINAL POSITION OF THE STUDY DOMAIN
  REAL                 :: COSTFUN            ! COST FUNCTION
  REAL    ,ALLOCATABLE :: GRADINT(:,:,:,:,:) ! GRADIENT OF COST FUNCTION
  CHARACTER(LEN=100)   :: OBSFILE            ! OBSERVATION FILE NAME

  INTEGER              :: COSSTEP            ! THE ITERATE STEPS BEFORE MIDDLE GRID LEVEL
  INTEGER              :: MIDGRID            ! MIDDLE GRID LEVEL WHERE THE ITERATE STEP CHANGED
  INTEGER              :: FINSTEP            ! THE ITERATE STEPS AFTER MIDDLE GRID LEVEL

  INTEGER              :: U_CMPNNT           ! U COMPONENT INDEX
  INTEGER              :: V_CMPNNT           ! V COMPONENT INDEX
  INTEGER              :: W_CMPNNT           ! W COMPONENT INDEX
  INTEGER              :: PRESSURE           ! PRESSURE INDEX
  INTEGER              :: TEMPRTUR           ! TEMPERATURE INDEX
  INTEGER              :: HUMIDITY           ! SPECIFIC HUMIDITY INDEX
!added by Juxiang for cloud optical depth
  INTEGER              :: CLOUDICE           ! CLOUD ICE INDEX
  INTEGER              :: CLOUDWAT           ! CLOUD WATER INDEX
  INTEGER              :: RAINCONT           ! RAIN CONTENT INDEX
  INTEGER              :: SNOWCONT           ! SNOW CONTENT INDEX
  INTEGER              :: GRAPCONT           ! GRAUPEL CONTENT INDEX
  
!added by shuyuan 20100721 for radar reflectivity
  INTEGER              :: ROUR_CMPNNT        ! DENSITY*RAIN WATER MIXING RATIO
  INTEGER              :: ROUS_CMPNNT        ! DENSITY*SNOW WATER MIXING RATIO
!
  INTEGER              :: XSL                ! X COORDINATE INDEX
  INTEGER              :: YSL                ! Y COORDINATE INDEX
  INTEGER              :: PSL                ! PRESSURE INDEX
  INTEGER              :: CSL                ! CORIOLIS FORCE INDEX
  INTEGER              :: DSL                ! DENSITY INDEX

  ! INTEGER ,ALLOCATABLE :: IDXRADWN(:,:)      ! GRID INDICES OF RADIAL WIND

  REAL                 :: XYTRANS            ! COEFFICIENT USED TO TRANSLATE THE X AND Y COORDINATE TO METERS
  REAL                 :: Z_TRANS            ! COEFFICIENT USED TO TRANSLATE THE Z COORDINATE TO METERS

  REAL    ,ALLOCATABLE :: WWW(:,:,:,:)       ! W COMPONENT
  REAL    ,ALLOCATABLE :: XXX(:,:)           ! DISTANCE OF HORIZONTAL DIMENSION 1
  REAL    ,ALLOCATABLE :: YYY(:,:)           ! DISTANCE OF HORIZONTAL DIMENSION 2
  REAL    ,ALLOCATABLE :: ZZZ(:,:,:,:)       ! HEIGHT OF GENERAL VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: PPP(:)             ! PRESSURE VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: COR(:,:)           ! CORIOLIS FREQUENCY
  REAL    ,ALLOCATABLE :: DEG(:,:)           ! DIRECTION ANGLE
  REAL    ,ALLOCATABLE :: DEN(:,:,:,:)       ! DENSITY
  REAL    ,ALLOCATABLE :: SCL(:)             ! SCALING THE PHYSICAL VARIABLE
  REAL    ,ALLOCATABLE :: SL0(:)             ! DEFAULT SCALING THE PHYSICAL VARIABLE
  REAL                 :: SCP(5)             ! SCALING XXX,YYY,ZZZ OR PPP,COR,DEN
  REAL                 :: ORIVTCL
  REAL    ,ALLOCATABLE :: XX0(:,:)           ! DISTANCE OF HORIZONTAL DIMENSION 1
  REAL    ,ALLOCATABLE :: YY0(:,:)           ! DISTANCE OF HORIZONTAL DIMENSION 2
  REAL    ,ALLOCATABLE :: ZZ0(:,:,:,:)       ! HEIGHT OF GENERAL VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: ZZB(:)       ! SIGMA LEVEL FOR VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: PP0(:)             ! PRESSURE VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: PPM(:)             ! MULTIGRID PRESSURE VERTICAL COORDINATE
  REAL    ,ALLOCATABLE :: CR0(:,:)           ! CORIOLIS FREQUENCY
  REAL    ,ALLOCATABLE :: DG0(:,:)           ! DIRECTION ANGLE
  REAL    ,ALLOCATABLE :: DN0(:,:,:,:)       ! DENSITY
! FOR OBSERVATION
  REAL                 :: OBSRADAR           ! THE OBSERVATION RATIO OF CONVENTION TO RADAR DATA
  REAL                 :: OBS_SFMR           ! THE OBSERVATION RATIO OF CONVENTION TO SFMR DATA
  REAL                 :: OBSREF           ! THE OBSERVATION RATIO OF REF
  REAL    ,ALLOCATABLE :: OBSPOSTN(:,:)      ! COORDINATE OF OBSERVATION POINT
  REAL    ,ALLOCATABLE :: OBSCOEFF(:,:)      ! INTERPOLATION COEFFICENT
  INTEGER ,ALLOCATABLE :: OBSIDXPC(:,:)      ! INDEX OF EVERY NODE PER CELL
  INTEGER ,ALLOCATABLE :: OBSSTATE(:)        ! NUMBER OF OBSERVATION FOR EVERY STATE
  REAL    ,ALLOCATABLE :: OBSVALUE(:)        ! OBSERVATION VALUE
  REAL    ,ALLOCATABLE :: OBSERROR(:)        ! OBSERVATION ERROR
  REAL    ,ALLOCATABLE :: OBSEINF1(:)        ! OBSERVATION EXTRA INFORMATION 1
  REAL    ,ALLOCATABLE :: OBSEINF2(:)        ! OBSERVATION EXTRA INFORMATION 2
  REAL    ,ALLOCATABLE :: OBSEINF3(:)        ! OBSERVATION EXTRA INFORMATION 3

  ! GPSMET WETDELAY DATA:
  INTEGER, PARAMETER :: MAX_GPS = 5000		! TEMPORARILY HARD CODED  !!changefrom 2000 to 5000 20100525 liu
  INTEGER :: NUM_GPS,I4T_GPS			! I4T_GPS: I4TIME OF Jan 1, 1970
  REAL    :: GPS_XYT(3,MAX_GPS),GPS_ELV(MAX_GPS),GPS_TIM(MAX_GPS), &
             GPS_ERR(MAX_GPS),GPS_TPW(MAX_GPS),GPS_WET(MAX_GPS)

  ! SURFACE PRESSURE:
  REAL    ,ALLOCATABLE :: P_SFC_F(:,:)
  
! FOR GRID POINT VARIABLE
  REAL    ,ALLOCATABLE :: GRDBKGD0(:,:,:,:,:)! GRID BACKGROUND VALUE
  REAL    ,ALLOCATABLE :: GRDBKGND(:,:,:,:,:)! GRID BACKGROUND VALUE
  REAL    ,ALLOCATABLE :: GRDANALS(:,:,:,:,:)! GRID ANALYSIS VALUE
  REAL    ,ALLOCATABLE :: TMPANALS(:,:,:,:,:)! GRID ANALYSIS VALUE

  REAL    ,ALLOCATABLE :: WWWOUT(:,:,:,:)    ! W COMPONENT FOR OUTPUT
  REAL    ,ALLOCATABLE :: DIFFTOUT(:,:,:,:,:)! GRID ANALYSIS VALUE FOR OUTPUR
  REAL    ,ALLOCATABLE :: Z_MAXGID(:)        ! VERTICAL LEVEL OF FINEST ANALYSIS GRID

  REAL                 :: PNLT0HY            ! INITIAL HYDROSTATIC CONDITION PENALTY COEFFICENT. ADDIED BY ZHONGJIE HE
  REAL                 :: PNLT_HY            ! HYDROSTATIC CONDITION PENALTY COEFFICENT. ADDIED BY ZHONGJIE HE
  REAL                 :: TAUL_HY            ! REDUCTION COEFFICENT OF HYDROSTATIC CONDITION PENALTY TERM, ADDIED BY ZHONGJIE HE
  REAL                 :: ENDHYLV            ! THE GRID LEVEL AFTER WHICH THE HYDROSTATIC CONDITION PENALTY TERM IS OMMITTED. ADDED BY ZHONGJIE HE
  REAL                 :: ENDGSLV            ! THE GRID LEVEL AFTER WHICH THE GEOSTROPHIC BALANCE PENALTY TERM IS OMMITTED. ADDED BY ZHONGJIE HE
  REAL                 :: LIMIT_3            ! THE LIMITATION OF HEIGHT TO DECIDE IN WHICH RANGE THE OBSERVATION IS AVIABLE. ADDED BY ZHONGJIE HE
  REAL                 :: LIMIT_4            ! THE LIMITATION OF TIME TO DECIDE IN WHICH RANGE THE OBSERVATION IS AVIABLE. ADDED BY ZHONGJIE HE

  ! ANALYSIS DOMAIN BY YUANFU XIE:
  INTEGER              :: ITIME2(2)          ! ANALYSIS TIME WINDOW

END MODULE PRMTRS_STMAS
